<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
//response.sendRedirect("common/login");
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>FinanceOrg</title>
			<script type="text/javascript" src="${path }/resource/js/jquery-1.8.3.min.js"></script>
			<script type="text/javascript" src="${path }/resource/js/mytools.js"></script>
			<script type="text/javascript" src="${path }/resource/layui/layui.js" ></script>
			<link rel="stylesheet" href="${path }/resource/layui/css/layui.css" />
			<script type="text/javascript" src="${path }/resource/js/ajaxfileupload.js"></script>
	</head>
<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	  <legend>FinanceOrg</legend>
	</fieldset>
	<form  class="layui-form layui-form-pane" onsubmit="javascripr:return false;" id="from1">
		<div class="layui-form-item">
			<input type="hidden" name="id" value="${obj.id}"/> <!--隐藏域id el表达式获取 -->
			<div class="layui-inline">
      			<label class="layui-form-label">机构名称:</label>
      			<div class="layui-input-inline">
					<input type="text" name="orgName"  class="layui-input" value="${obj.orgName}" id="orgName"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">机构类型:</label>
      			<div class="layui-input-inline">
      			<select lay-filter="orgType"  name="orgType" >
      			<option value="">请选择</option>
				</select>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">机构代码:</label>
      			<div class="layui-input-inline">
					<input type="text" name="orgCode" class="layui-input" value="${obj.orgCode}" id="orgCode"/>
	 			</div>
			</div>
			</div>
			
	<div class="layui-form-item">
			<div class="layui-inline">
      			<label class="layui-form-label">所属区域:</label>
      	<div class="layui-input-inline">
      		<select lay-filter="area" id="autoselect2" name="area" >
      			<option value="">请选择市</option>
			</select>
	 	</div>
	 	<div class="layui-input-inline">
	 		<select name="zone" >
	 			<option value="">请选择区</option>
	 	</select>
		</div>
		</div>
		</div>
			<div class="layui-form-item">
			<div class="layui-inline">
      			<label class="layui-form-label">成立日期:</label>
      			<div class="layui-input-inline">
					<input type="text" name="upDate"  class="layui-input" value="${obj.upDate}" id="upDate"  onclick="layui.laydate({elem: this})"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">法定人:</label>
      			<div class="layui-input-inline">
					<input type="text" name="lawRepresent"  class="layui-input" value="${obj.lawRepresent}" id="lawRepresent"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">注册资金:</label>
      			<div class="layui-input-inline">
					<input type="text" name="regMoney"  lay-verify="number" class="layui-input" 
					<c:if test="${obj.regMoney ne null}">
					value="${obj.regMoney}"
					</c:if>
					<c:if test="${obj.regMoney eq null}">
					value="0"
					</c:if>
					id="regMoney"/>
	 			</div>
			</div>
			</div>
				
			<div class="layui-form-item">	
			<div class="layui-inline">
      			<label class="layui-form-label">工商注册号:</label>
      			<div class="layui-input-inline">
					<input type="text" name="icbcRegNo"  class="layui-input" value="${obj.icbcRegNo}" id="icbcRegNo"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">国税务登记号:</label>
      			<div class="layui-input-inline">
					<input type="text" name="gtaxNo"  class="layui-input" value="${obj.gtaxNo}" id="gtaxNo"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">地税务登记号:</label>
      			<div class="layui-input-inline">
					<input type="text" name="dtaxNo"  class="layui-input" value="${obj.dtaxNo}" id="dtaxNo"/>
	 			</div>
			</div>
			</div>
			
			<div class="layui-form-item  layui-form-text">
      			<label class="layui-form-label">经营范围:</label>
      			<div class="layui-input-block">
					<textarea   name="manageScope"  class="layui-textarea" value="${obj.manageScope}"  placeholder="请输入内容"></textarea>
	 			</div>
	 			</div>
	 		<div class="layui-form-item layui-form-text">
      			<label class="layui-form-label layui-form-text">机构介绍:</label>
      			<div class="layui-input-block">
					<textarea  name="orgIntro"  class="layui-textarea" placeholder="请输入内容" value="${obj.orgIntro}" id="orgIntro"></textarea>
	 			</div>
			</div>
			<div class="layui-form-item layui-form-text">
      			<label class="layui-form-label">主要产品:</label>
      			<div class="layui-input-block">
					<input type="text" name="mainProduct" placeholder="请输入内容"  class="layui-textarea" value="${obj.mainProduct}" id="mainProduct"/>
	 			</div>
			</div>
			
			<div class="layui-form-item">
			<div class="layui-inline">
      			<label class="layui-form-label">机构logo:</label>
		      <div class="layui-input-inline">
		      	<div style="width:60px;height:60px;border: 1px solid" onclick="importChances()">
				 <img alt="" src="${obj.orgLogo}" style="width:60px;height:60px;" id="orgLogoimg" />
				</div>
				<input type="hidden" name="orgLogo" class="form-control" value="${obj.orgLogo}" id="orgLogo"  />
				<input type="file" name="file" style="display: none;"   id="chanceUploadId" onchange="onchangeFile()" />
			 </div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">注册地址:</label>
      			<div class="layui-input-inline">
					<input type="text" name="regAddr" class="layui-input" value="${obj.regAddr}" id="regAddr"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">联系电话:</label>
      			<div class="layui-input-inline">
					<input type="text" name="orgTel" lay-verify="phone" class="layui-input" value="${obj.orgTel}" id="orgTel"/>
	 			</div>
			</div>
			</div>
			<div class="layui-form-item">
			<div class="layui-inline">
      			<label class="layui-form-label">传真:</label>
      			<div class="layui-input-inline">
					<input type="text" name="orgFax"  class="layui-input" value="${obj.orgFax}" id="orgFax"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">邮箱:</label>
      			<div class="layui-input-inline">
					<input type="text" name="orgEmail" lay-verify="email" class="layui-input" value="${obj.orgEmail}" id="orgEmail"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">网站:</label>
      			<div class="layui-input-inline">
					<input type="text" name="orgSide"  class="layui-input" value="${obj.orgSide}" id="orgSide"/>
	 			</div>
			</div>
			</div>
			<div class="layui-form-item">
			<div class="layui-inline">
      			<label class="layui-form-label">联系人:</label>
      			<div class="layui-input-inline">
					<input type="text" name="linkman"  class="layui-input" value="${obj.linkman}" id="linkman"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">邮政编码:</label>
      			<div class="layui-input-inline">
					<input type="text" name="zipCode" class="layui-input" value="${obj.zipCode}" id="zipCode"/>
	 			</div>
			</div>
			<div class="layui-inline">
      			<label class="layui-form-label">英文名称:</label>
      			<div class="layui-input-inline">
					<input type="text" name="engName" class="layui-input" value="${obj.engName}" id="engName"/>
	 			</div>
			</div>
			</div>
			<div class="layui-form-item">
			<div class="layui-inline">
      			<label class="layui-form-label">办公地点:</label>
      			<div class="layui-input-inline">
					<input type="text" name="jobAddr" class="layui-input" value="${obj.jobAddr}" id="jobAddr"/>
	 			</div>
			</div>
		</div>
 <div class="layui-form-item">
    <div class="layui-input-block">
      <input  type="button" value="上报"  class="layui-btn"  lay-submit="" lay-filter="form1">
      <input type="reset" class="layui-btn layui-btn-primary" value="重置">
    </div>
  </div>
	</form>
	<script type="text/javascript">
	//绑定文件的点击事件
	function importChances(){
		$("#chanceUploadId").click();
	}
	//file改变事件触发就提交文件
	function onchangeFile(){
		//提交文件
		 submitData();
		 //$("#orgLogo").val($("#chanceUploadId").val());
	}
	//提交文件
	function submitData(){
		$.ajaxFileUpload({
			url : "${path }/user/finance/FinanceOrg/uploadImg",
			type : "POST",
			secureuri : false,// 一般设置为false
			fileElementId : "chanceUploadId",
			dataType : "json",
			success : function(data) {
				$("#orgLogo").val(data.info);
				$("#orgLogoimg").attr("src",data.info);
        	}
			});
		}
	var $form; 
	var layer;
	var form;
	layui.use(['form', 'layedit', 'laydate'], function(){
		  form = layui.form();
		  layer = layui.layer;
		  layedit = layui.layedit;
		  laydate = layui.laydate;
		  $form = $('form');
		 //加载市级
		 loadArea();
		 loadorgType();
		 //监听提交
		  form.on('submit(form1)', function(data){
			  //alert(JSON.stringify(data.field));
			  mytooljs.initForm({
					idSelecter :"#from1", //表单id选择器
					sendurl:"${path }/user/finance/FinanceOrg/addOrModify",//发送请求的地址
					data:data.field,//传数据过去
					afterload:function(){//请求成功后回调
						layer.open({
					       	  content: '保存成功'
					       	  ,btn: ['确定']
					       	  ,yes: function(index, layero){
					       		parent.mjs.search();
					       		parent.layer.closeAll();
					       	  },cancel:function(index, layer){
								parent.mjs.refCurr();
					       		parent.layer.closeAll();
							}
					       	}); 
					}
				});
		    return false;
		  });
		});

    //加载机构类型
   function loadorgType() {
       var orgTypeHtml = '';
       ///准备发射ajax请求得到数据
       var url = '${path}/common/Dictionary/showSelect';
       var data = {"dicType":"机构类型"};
       $.ajax({
	  		'type':'post',
	  		'url':url,
	  		'data':data,
	  		'dataType':'json',
	  		'success':function(data,status){
	  			for(var i=0;i<data.rows.length;i++){
	  				orgTypeHtml+="<option value='"+data.rows[i].dicValue+"' ";
	  				orgTypeHtml+="  >"+data.rows[i].dicValue+"</option>";
	  			}
	  			$form.find('select[name=orgType]').html(orgTypeHtml).parent().show();
	  	        form.render();
	  		}
	  	});
   }
	
     //加载市数据
    function loadArea() {
        var areaHtml = '';
        ///准备发射ajax请求得到数据
        var url = '${path}/common/Dictionary/showSelect';
        var data = {"dicType":"所在区域"};
        $.ajax({
	  		'type':'post',
	  		'url':url,
	  		'data':data,
	  		'dataType':'json',
	  		'success':function(data,status){
	  			for(var i=0;i<data.rows.length;i++){
	  				areaHtml+="<option value='"+data.rows[i].dicValue+"' ";
	  				areaHtml+="  >"+data.rows[i].dicValue+"</option>";
	  			}
	  			$form.find('select[name=area]').html(areaHtml).parent().show();
	  	        form.render();
	  	        form.on('select(area)', function(data) {
	  	            var value = data.value;
	  	            loadZone(value);
	  	        });
	  		}
	  	});
    }
     //加载县/区数据
    function loadZone(zone) {
        var zoneHtml = '';
        var url = '${path}/common/Dictionary/showSelect';
        var data = {"dicType":zone};
        $.ajax({
	  		'type':'post',
	  		'url':url,
	  		'data':data,
	  		'dataType':'json',
	  		'success':function(data,status){
	  		if(data.rows.length>0){
	  			for(var i=0;i<data.rows.length;i++){
	  				zoneHtml+="<option value='"+data.rows[i].dicValue+"' ";
	  				zoneHtml+="  >"+data.rows[i].dicValue+"</option>";
	  			}
	  		}else{
	  			zoneHtml+='<option value="">请选择区</option>';
	  		}
	  			$form.find('select[name=zone]').html(zoneHtml).parent().show();
	  	        form.render();
	  	        form.on('select(zone)', function(data) {
	  	            var value = data.value;
	  	            loadZone(value);
	  	        });
	  		}
	  	});
        form.on('select(zone)', function(data) {
            //console.log(data);
        });
    }
	
	
	
		</script>
	</body>
</html>
